$(function() {

    fffCommerce.api.Products.browse = function(searchText,callback){
	var listProducts = [];
	var newProduct = {
	    uid:1,
	    name:"Product A(" + searchText + ")" ,
	    shortName:"Prod B",
	    price:20.0,
	    description:"best product A available",
	    thumbnail:"http://duckduckgo.com/sduck.v104.png"
	};
	var anotherProduct = {
	    uid:1,
	    name:"Product A(" + searchText + ")" ,
	    shortName:"Prod A",
	    price:10.0,
	    description:"best product A available",
	    thumbnail:"http://duckduckgo.com/sduck.v104.png"
	};
	listProducts.push(newProduct);
	listProducts.push(anotherProduct);
	callback({data:listProducts});
    };
    
    $('<input type="text" id="query"/>&nbsp;<button id="btnSearch" type="button">Search</button><span id="indicatorSearch"></span>').appendTo('#search');
    
    $('#btnSearch').click(function() {
		$('#indicatorSearch').html(fffCommerce.ui.indicator + ' Loading, please wait...');
		$('#list').empty();
		fffCommerce.api.Products.browse($('#query').val(), function(e) {
		    $('#indicatorSearch').empty();
			if (e.data) {
				$('body').trigger(fffCommerce.events.SHOW_LIST, [e.data]);
			} else {
				$('#list').html('<b>Error:</b> ' + e.error);
			}
		});
	}, false);
});